
import com.consorzioimpresa.resuite.domain.Role;

import com.consorzioimpresa.resuite.domain.User;
import com.consorzioimpresa.resuite.domain.UserRole;
class BootStrap {
	def springSecurityService
    def init = { servletContext ->
		//init Role
		def userRole = Role.findByAuthority('ROLE_CDIMPRESA') ?: new Role(authority: 'ROLE_CDIMPRESA').save(failOnError: true)
		def adminRole = Role.findByAuthority('ROLE_ADMIN') ?: new Role(authority: 'ROLE_ADMIN').save(failOnError: true)
		//Admin USer
		def adminUser = User.findByUsername('admin') ?: new User(
			username: 'admin',
			password: springSecurityService.encodePassword('consulenti2012!'),
			enabled: true,
			email: 'admin@resuite.it').save(failOnError: true)

	if (!adminUser.authorities.contains(adminRole)) {
		UserRole.create adminUser, adminRole
	}
		
    }
    def destroy = {
    }
}
